<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<%@include file="../../commons/meta.jsp" %> 
<link rel="stylesheet" href="${ctx}assets/plugins/pure/pure-min.css" media="all" />
<link rel="stylesheet" href="${ctx}assets/plugins/ztree/latest/css/demo.css" type="text/css">
<link rel="stylesheet" href="${ctx}assets/plugins/ztree/latest/css/zTreeStyle/zTreeStyle.css" type="text/css">
<!-- <script type="text/javascript" src="assets/plugins/ztree/latest/js/jquery-1.4.4.min.js"></script> -->
<script type="text/javascript" src="${ctx}assets/plugins/ztree/latest/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${ctx}assets/plugins/ztree/latest/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript">
debugs("${ctx} --- role-auth.jsp");
var zTree ;
function validateForm(){
	$("#authCodes").val("");
    if(empty($("#roleCode").val())){
    	alertError('<fmt:message key='Page.please.try.again'/>');
		return false;
    }
    
    var authCodes = "";
	zTree = $.fn.zTree.getZTreeObj("treeDemo");
	var nodes = zTree.getCheckedNodes(true);
	debugs(nodes);
	for (var i=0, l=nodes.length; i<l; i++) {
		debugs(nodes[i].id);
		authCodes += nodes[i].id+",";
	}
	debugs(authCodes);
	$("#authCodes").val(authCodes);
   /*  if(empty($("#authCodes").val())){
    	alertError('请授予权限!');
		return false;
    } */

    $("#forms").submit();   
} 

//关闭弹出框 
jQuery(document).ready(function() { 
	$("#back_btn").click(function() {
		window.location.href="${ctx}admin/adminrole/"
	});
}); 
</script> 
<style type="text/css">
div.zTreeDemoBackground,ul.ztree{
	width: 99%;
	height: 600px;
}
div.zTreeDemoBackground{height:265px;}
ul.ztree{height:560px;margin-top:0px;background: white;border:0px;}
*{margin: 0;padding: 0;font-family:"微软雅黑"!important;}
ul li{list-style: none;}
a{text-decoration:none;}
img{border:0;}
.listul-mask a:hover{background:rgb(42,42,42);}
</style>
</head>
<body>
	<%@include file="../../commons/head.jsp" %> 
	<div class="content">
		<%@include file="../../commons/menu.jsp" %> 
		<!--右侧展示部分-->
		<div class="right-zq">
			<!--center content-->
			<div class="dynamic">
        		<div class="role dynamiclayer" style="display:block;">
        		<div class="title orange2"><span class="left"><fmt:message key='User.permissions'/></span><label> > </label><span><fmt:message key='role'/></span><label> > </label><span><fmt:message key='Assign.permissions'/></span></div>
					<form class="" id="forms" method="post" action="${ctx}admin/adminrole/auth">
						<div class="news-table" style="height:380px;">
							<table style="height:380px;">
								<tr>
									<td class="item"><fmt:message key='Character.code'/></td>
           							<td width="40%"><input id="roleCode" name="roleCode" type="text"  placeholder="" value="${obj.roleCode }" readonly="readonly"/></td>
									<td>
       								<input id="authCodes" name="authCodes" type="hidden" readonly="readonly"/>
									</td> 
								</tr>  
								<tr>
									<td class="item"><fmt:message key='permissions'/></td>
									<td width="40%" style="height: 600px">
           							  <div class="zTreeDemoBackground left">
										<ul id="treeDemo" class="ztree"></ul>
									</div>
           							 </td>
									<td> </td>
								</tr> 
								<tr>
									<td></td>
									<td width="40%">
										<button class="orange2" type="button" onclick="validateForm()">
											<fmt:message key='sys.save'/>&nbsp;<i class="fa fa-floppy-o"></i>
										</button>
										&nbsp;&nbsp;
										<button class="orange2" type="button" id="back_btn">
											<fmt:message key='sys.retu'/>&nbsp;<i class="fa fa-undo"></i>
										</button>
									</td>
									<td></td>
								</tr>
							</table>
						</div>
					</form>
				</div>
			</div>
			<!--center content over-->
		</div>
	</div>
  <script> 
		var setting = {
			check: { enable: true, chkDisabledInherit: true,chkDisabledInherit :false,inheritParent:false, inheritChildren:false },
			data: { simpleData: { enable: true } }
		};
		var json = '${allAuthJson}';
		console.log(json);
		json = JSON.parse(json);
		console.log(json);
		var zNodes =json;
		function setCheck() {
			zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			type = { "Y" : "s", "N" : "s" };
			zTree.setting.check.chkboxType = type;
			var nodes = zTree.getSelectedNodes();
			for (var i=0, l=nodes.length; i<l; i++) {
				debugs(nodes[i]);
			}
		}
		
		$(document).ready(function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			setCheck(); 
		});
	</SCRIPT>
<%@include file="../../commons/footpop.jsp" %> 
<!-- 页尾，提示消息 -->
<jsp:include page="../../commons/foot_message.jsp"></jsp:include> 
</body>
</html>
